<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');

/**
 * 地区控制器
 * @author wwj
 * @version 1.0.1 2013-2-18
 */
class District extends MY_Controller
{
	function __construct()
	{
		parent::__construct();
		
		// 后台登录验证
		$this->check_login();
		$this->load->model('district_m');
		
		// @FIXME 验证权限，页面视图模型还要调用此控制器，可以将此权限加到编辑，添加，删除方法中
		//$this->verify_purview(PURVIEW_DISTRICT);

		// 加载友情链接的语言包
		//$this->load->language('district');
	}
	
	/**
	 * 地区管理默认方法，指向栏目列表页
	 */
	function index()
	{
		//$this->column_manage();
		
	}
	
	protected function get_district_by_upid($upid = 0)
	{
		$upid = (int)$upid;
		return $this->district_m->get_district(array('upid' => $upid));
	}
	
	function get_district_as_option()
	{
		$district = array('option' => '', 'subid' => '');
		$upid = $this->input->post('upid');
		$upid = FALSE == $upid ? 0 : $upid;
		$selected_district = $this->input->post('selected');
		$selected_district = FALSE == $selected_district ? '' : $selected_district;
		$result = $this->get_district_by_upid($upid);
		if (!empty($result))
		{
			$district['option'] = '';
			foreach ($result as $value)
			{
				$selected = '';
				if ($selected_district == $value['name'])
				{
					$selected = ' selected="selected" ';
					$district['subid'] = $value['id'];
				}
				$district['option'] .= '<option id="L' . $value['level'] . '-' . $value['id'] . '" value="' . $value['name'] . '" '.$selected.'>' . $value['name'] . '</option>';
			}
			echo json_encode($district);
			return;
		}
		else
		{
			echo json_encode($district);
			return ;
		}
	}

}

/* End of file column.php */
/* Location: ./application/controllers/column.php */